home *** CD-ROM | disk | FTP | other *** search
/ Champak 83 / (Vol 83) My Disc.iso / Games / hello_kitty.swf / scripts / frame_14 / DoAction.as
Text File  |  2008-08-07  |  7KB  |  303 lines

  1. function enemyBrain7()
  2. {
  3.    var i = 0;
  4.    while(i < 10)
  5.    {
  6.       var name = "enemy" + i;
  7.       var ob = game[name];
  8.       getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
  9.       if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
  10.       {
  11.          moveChar(ob,ob.xMove,ob.yMove);
  12.       }
  13.       else
  14.       {
  15.          ob.xMove = - ob.xMove;
  16.          ob.yMove = - ob.yMove;
  17.       }
  18.       if(!_root.infiniteLife)
  19.       {
  20.          var xdist = ob.x - char.x;
  21.          var ydist = ob.y - char.y;
  22.          if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
  23.          {
  24.             _root.lifes -= 1;
  25.             youdied.gotoandplay(2);
  26.             mylifes.gotoandstop(_root.lifes);
  27.             if(_root.lifes == 0)
  28.             {
  29.                removeMovieClip(_root.tiles);
  30.                gotoAndStop(35);
  31.             }
  32.             if(!_root.hurt)
  33.             {
  34.                char.clip.gotoAndPlay("hurt");
  35.                return undefined;
  36.             }
  37.          }
  38.       }
  39.       i++;
  40.    }
  41. }
  42. function detectKeys_7()
  43. {
  44.    var ob = _root.char;
  45.    var keypressed = false;
  46.    if(key.isDown(39))
  47.    {
  48.       keyPressed = _root.moveChar7(ob,1,0);
  49.    }
  50.    else if(key.isDown(37))
  51.    {
  52.       keyPressed = _root.moveChar7(ob,-1,0);
  53.    }
  54.    else if(key.isDown(38))
  55.    {
  56.       keyPressed = _root.moveChar7(ob,0,-1);
  57.    }
  58.    else if(key.isDown(40))
  59.    {
  60.       keyPressed = _root.moveChar7(ob,0,1);
  61.    }
  62.    if(!KeyPressed)
  63.    {
  64.       ob.clip.mychar.gotoandstop(1);
  65.    }
  66.    else
  67.    {
  68.       ob.clip.mychar.play();
  69.    }
  70.    enemyBrain7();
  71. }
  72. function moveChar7(ob, dirx, diry)
  73. {
  74.    getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
  75.    if(diry == -1)
  76.    {
  77.       if(ob.upleft and ob.upright)
  78.       {
  79.          ob.y += ob.speed * diry;
  80.       }
  81.       else
  82.       {
  83.          ob.y = ob.ytile * game.tileH + ob.height;
  84.       }
  85.    }
  86.    if(diry == 1)
  87.    {
  88.       if(ob.downleft and ob.downright)
  89.       {
  90.          ob.y += ob.speed * diry;
  91.       }
  92.       else
  93.       {
  94.          ob.y = (ob.ytile + 1) * game.tileH - ob.height;
  95.       }
  96.    }
  97.    getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
  98.    if(dirx == -1)
  99.    {
  100.       if(ob.downleft and ob.upleft)
  101.       {
  102.          ob.x += ob.speed * dirx;
  103.       }
  104.       else
  105.       {
  106.          ob.x = ob.xtile * game.tileW + ob.width;
  107.       }
  108.    }
  109.    if(dirx == 1)
  110.    {
  111.       if(ob.upright and ob.downright)
  112.       {
  113.          ob.x += ob.speed * dirx;
  114.       }
  115.       else
  116.       {
  117.          ob.x = (ob.xtile + 1) * game.tileW - ob.width;
  118.       }
  119.    }
  120.    ob.clip._x = ob.x;
  121.    ob.clip._y = ob.y;
  122.    ob.clip.gotoandstop(dirx + diry * 2 + 3);
  123.    ob.xtile = Math.floor(ob.clip._x / game.tileW);
  124.    ob.ytile = Math.floor(ob.clip._y / game.tileH);
  125.    var itemname = game["item" + ob.ytile + "_" + ob.xtile];
  126.    if(itemname and ob == _root.char)
  127.    {
  128.       game.points += itemname.points;
  129.       removeMovieClip(itemname.clip);
  130.       game.items[itemname.position] = 0;
  131.       delete game["item" + ob.ytile + "_" + ob.xtile];
  132.    }
  133.    if(game.points == 1)
  134.    {
  135.       openwallname = "t_1_6";
  136.       game.clip[openwallname].gotoandstop(1);
  137.       openwallname = "t_3_3";
  138.       game.clip[openwallname].gotoandstop(1);
  139.       openwallname2 = "t_2_3";
  140.       game.clip[openwallname2].gotoandstop(1);
  141.       openwallname3 = "t_1_3";
  142.       game.clip[openwallname3].gotoandstop(1);
  143.       game.Tile7.prototype.walkable = true;
  144.    }
  145.    if(game.points == 1)
  146.    {
  147.       opendoorname = "t_" + unlockY + "_" + unlockX;
  148.       game.clip[opendoorname].gotoandstop(4);
  149.       game.Tile2.prototype.walkable = true;
  150.    }
  151.    if(_root.char.ytile == unlockY && _root.char.xtile == unlockX)
  152.    {
  153.       trace("here");
  154.       _root.tempLv = 8;
  155.       removeMovieClip(_root.tiles);
  156.       gotoAndStop(15);
  157.    }
  158.    if(_root.char.ytile == 7 && _root.char.xtile == 2 || _root.char.ytile == 1 && _root.char.xtile == 9 || _root.char.ytile == 5 && _root.char.xtile == 4 || _root.char.ytile == 0 && _root.char.xtile == 0 || _root.char.ytile == 7 && _root.char.xtile == 2 || _root.char.ytile == 7 && _root.char.xtile == 3)
  159.    {
  160.       _root.char.speed = 0.5;
  161.    }
  162.    else
  163.    {
  164.       _root.char.speed = 3;
  165.    }
  166.    return true;
  167. }
  168. function getMyCorners(x, y, ob)
  169. {
  170.    ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
  171.    ob.upY = Math.floor((y - ob.height) / game.tileH);
  172.    ob.leftX = Math.floor((x - ob.width) / game.tileW);
  173.    ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
  174.    ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
  175.    ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
  176.    ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
  177.    ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
  178. }
  179. if(_root.tempLv == 8)
  180. {
  181.    gotoAndStop(16);
  182. }
  183. getURL("FSCommand:allowscale",true);
  184. myMap1 = [[6,0,1,0,1,0,1,0,1,1],[1,0,0,0,0,0,0,0,0,6],[1,0,1,0,1,0,1,0,1,0],[1,0,1,0,0,0,1,0,1,1],[1,1,1,1,0,1,1,1,1,1],[1,0,0,0,6,0,0,1,1,1],[1,1,1,0,1,1,1,0,0,1],[1,2,6,6,0,0,0,0,0,1],[1,1,1,1,1,1,1,1,1,1]];
  185. game = {tileW:45,tileH:45,currentMap:1,points:0,wallkey:false};
  186. game.Tile0 = function()
  187. {
  188. };
  189. game.Tile0.prototype.walkable = true;
  190. game.Tile0.prototype.frame = 1;
  191. game.Tile1 = function()
  192. {
  193. };
  194. game.Tile1.prototype.walkable = false;
  195. game.Tile1.prototype.frame = 2;
  196. game.Tile2 = function()
  197. {
  198. };
  199. game.Tile2.prototype.walkable = false;
  200. game.Tile2.prototype.frame = 3;
  201. game.Tile5 = function()
  202. {
  203. };
  204. game.Tile5.prototype.walkable = false;
  205. game.Tile5.prototype.frame = 5;
  206. game.Tile6 = function()
  207. {
  208. };
  209. game.Tile6.prototype.walkable = true;
  210. game.Tile6.prototype.frame = 6;
  211. game.Tile7 = function()
  212. {
  213. };
  214. game.Tile7.prototype.walkable = false;
  215. game.Tile7.prototype.frame = 2;
  216. unlockY = 7;
  217. unlockX = 1;
  218. char = {xtile:8,ytile:6,speed:3};
  219. startingXtile = char.xtile;
  220. startingYtile = char.ytile;
  221. mylifes.gotoandstop(_root.lifes);
  222. myEnemies = [[1,1,2],[1,3,2],[3,3,1],[3,5,5],[3,2,7],[1,7,1],[2,5,2]];
  223. game.Enemyp1 = function()
  224. {
  225. };
  226. game.Enemyp1.prototype.xMove = 0;
  227. game.Enemyp1.prototype.yMove = 1;
  228. game.Enemyp1.prototype.speed = 1.5;
  229. game.Enemyp2 = function()
  230. {
  231. };
  232. game.Enemyp2.prototype.xMove = 0;
  233. game.Enemyp2.prototype.yMove = 1;
  234. game.Enemyp2.prototype.speed = 0.5;
  235. game.Enemyp3 = function()
  236. {
  237. };
  238. game.Enemyp3.prototype.xMove = 1;
  239. game.Enemyp3.prototype.yMove = 0;
  240. game.Enemyp3.prototype.speed = 1;
  241. game.Enemyp4 = function()
  242. {
  243. };
  244. game.Enemyp4.prototype.xMove = 0;
  245. game.Enemyp4.prototype.yMove = 1;
  246. game.Enemyp4.prototype.speed = 1.5;
  247. game.Enemyp5 = function()
  248. {
  249. };
  250. game.Enemyp5.prototype.xMove = 1;
  251. game.Enemyp5.prototype.yMove = 0;
  252. game.Enemyp5.prototype.speed = 0.5;
  253. myItems = [[1,1,0],[2,3,0],[3,5,0],[4,7,0]];
  254. myRandom = math.random() * 3 + 1;
  255. myRandom = math.round(myRandom);
  256. game.Item1 = function()
  257. {
  258. };
  259. if(myRandom == 1)
  260. {
  261.    game.Item1.prototype.points = 1;
  262. }
  263. else
  264. {
  265.    game.Item1.prototype.points = 0;
  266. }
  267. game.Item2 = function()
  268. {
  269. };
  270. if(myRandom == 2)
  271. {
  272.    game.Item2.prototype.points = 1;
  273. }
  274. else
  275. {
  276.    game.Item2.prototype.points = 0;
  277. }
  278. game.Item3 = function()
  279. {
  280. };
  281. if(myRandom == 3)
  282. {
  283.    game.Item3.prototype.points = 1;
  284. }
  285. else
  286. {
  287.    game.Item3.prototype.points = 0;
  288. }
  289. game.Item4 = function()
  290. {
  291. };
  292. if(myRandom == 4)
  293. {
  294.    game.Item4.prototype.points = 1;
  295. }
  296. else
  297. {
  298.    game.Item4.prototype.points = 0;
  299. }
  300. _root.buildMap(_root["myMap" + game.currentMap]);
  301. stop();
  302. trace("lv7 loaded");
  303.